Lesson 3 - newbie exercise

Read the code in each section and do the following -

  1. Add comments to explain the code
  2. Suggest test data to test the code
  3. Make the suggested changes.

The answers will only say what the code does and how to make the suggested change.


def convertCurrancy(amount, rate):
	return amount * rate


Suggested change - Write a new function called poundsToDollar(amount) which will convert pounds to dollars. It should use the convertCurrancy(amount, rate) to perform the calulation.

Toggle answer

for i in range(10, 20)
	# hint - % is called modulus and will return the remainder of division. 
	# see related links for more help!
	if (i % 2) == 0:
		print i, " is even"
	else:
		print i, " is odd"
		

Suggested changes - create a new function called oddEven(start, end). Add the above code to that function and call the function with at least 2 sets of test data.

Toggle answer

def x(z,y):
	if z > y: return z
	else: return y


Suggested changes - Change the names to make it more readable. Copy the changed version and produce it's opposite. Then test it by combining the two functions together as much as possible

Toggle answer